package bitwiseOperation;

//https://leetcode.cn/problems/single-number-ii/description/
public class l_137 {
    public int singleNumber(int[] nums) {
        //统计所有数字每个比特位的1的数量
        //如果数量不是3的倍数那么目标数字该比特位就为1
        int ans = 0;
        for(int i = 0; i < 32; i++)
        {
            int count = 0;
            for(int x: nums)
            {
                if(((x >> i) & 1) == 1)
                    count++;
            }
            if(count % 3 == 1)
                ans |= 1 << i;
        }
        return ans;
    }
}
